import { createApp } from "vue";

import App from "./匿名,具名插槽/App.vue";
// import App from "./App.vue";
// import router from './router/index同源测试'

import router from './router'
import { createPinia } from "pinia";
//import { createPinia } from "./pinia的使用,pinia用来替代vuex/mini-pinia/createPinia";
// import goodsStore from "./pinia的使用,pinia用来替代vuex/mini-pinia/goods";
import { createPersistedState } from 'pinia-plugin-persistedstate'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'animate.css';
import mitt from 'mitt'

import nub, { aa, ss } from './hooks/dd'
import directives from './directives'
import plugins from './vue3插件的使用'
const app = createApp(App)
console.log(app.config.globalProperties,4563);
app.config.globalProperties.myName = 'globalName';
app.config.errorHandler = (err, instance, info) => {
  console.log(err, instance, info,"errorHandler");
}
app.config.performance=true
const piniaStore = createPinia()
piniaStore.use(createPersistedState({
  auto: true,
}))

//实现pinia插件
// piniaStore.use(({ store }) => {
//   console.log(store, 5555);
//   let local = JSON.parse(localStorage.getItem(`${store.$id}pinia`))
//   if (local) { store.$state = local }
//   store.$subscribe(({ storeId: id }, state) => {
//     localStorage.setItem(`${id}pinia`, JSON.stringify(state))
//   })
//   store.$onAction(() => { //埋点
    
//   })
//   return { a: 1 } //把返回值合并到store中
//   //插件的核心就是利用$subscribe和$onAction
// })

app.use(piniaStore)
app.use(plugins, ['table1'])//第二个参数是按需引入,没有就是全部引入
app.provide('eventBus', mitt())
// 看(router的hash和history原理)的效果的时候把app.use(router)注释了
app.use(router)

app.use(ElementPlus)
//全局注册指令
for (let key in directives) {
  app.directive(key, directives[key])
}

app.mount("#app");
//在vue中数据更新是组件级别的

// const goods = goodsStore()
// console.log(goods,500000);